package com.tanhua.dubbo.server.api;


import com.alibaba.dubbo.config.annotation.Service;

import com.tanhua.dubbo.server.pojo.Audio;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;


@Service(version = "1.0.0")
@Slf4j
public class AudioApiImpl implements AudioApi {
    @Autowired
     private MongoTemplate mongoTemplate;

    @Override
    public Boolean saveSound(Audio audio) {
        if(audio.getUserId() == null){
            return false;
        }

        audio.setId(ObjectId.get());
        audio.setCreated(System.currentTimeMillis());


        this.mongoTemplate.save(audio);

         return true;
    }

    @Override
    public List<Audio> querySoundList(Long userId) {
        Query query = Query.query(Criteria.where("userId").ne(userId));
        return this.mongoTemplate.find(query, Audio.class);
    }
}
